package org.example.app.bean;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 商品销售数据累加器 - 用于Flink聚合操作
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProductSalesAccumulator {
    
    // 商品基本信息
    public String productId;
    public String productName;
    public String categoryId;
    public String categoryName;
    public String brandId;
    public String brandName;
    public String shopId;
    public String shopName;
    
    // 累计度量值
    public Double totalSalesAmount = 0.0;
    public Long totalSalesCount = 0L;
    public Long totalVisitorCount = 0L;
    public Double avgPrice = 0.0;
    public Integer count = 0;
    
    // 窗口时间信息
    public Long windowStart;
    public Long windowEnd;
    
    /**
     * 重置累加器
     */
    public void reset() {
        this.totalSalesAmount = 0.0;
        this.totalSalesCount = 0L;
        this.totalVisitorCount = 0L;
        this.avgPrice = 0.0;
        this.count = 0;
    }
    
    /**
     * 计算平均价格
     */
    public void calculateAvgPrice() {
        if (totalSalesCount > 0) {
            this.avgPrice = totalSalesAmount / totalSalesCount;
        }
    }
}